package com.arron.state;
//透支状态：具体状态类
public class OverDraftState extends AccountState{
    public OverDraftState(AccountState state) {
        super.acc =state.acc;
    }
    @Override
    public void deposit(double amount) {
        super.acc.setBalance(super.acc.getBalance()+amount);
        stateCheck();
    }

    @Override
    public void withdraw(double amount) {
        super.acc.setBalance(super.acc.getBalance()-amount);
    }

    @Override
    public void computerInterest() {
        System.out.println("透支状态，计算利息！");
    }
    //状态转换
    @Override
    public void stateCheck() {
        if(super.acc.getBalance()>0){
            super.acc.setState(new NormalState(this));
        }
        else if(acc.getBalance()==-2000){
            acc.setState(new RestrictedState(this));
        }
        else if(acc.getBalance()<-2000){
            System.out.println("操作受限！");
        }
    }
}
